<?php 
	$seller = \Session::get('seller', false); 
	$cid = 0;
	$entity_name = '文章';
	if(isset($item) && $item){
		if($item->category_id == $seller->page_category){
			$cid = $item->category_id;
			$entity_name = '页面';
		}else if($item->category_id == $seller->article_category){
			$cid = $seller->article_category;
		}else if($item->category_id == $seller->case_category){
			$cid = $seller->case_category;
		}else if($item->category_id == $seller->ad_category){
			$cid = $seller->ad_category;
		}
	}else{
		if(\Input::get('action',  'article') == 'article'){
			$cid = $seller->article_category;
		}else if(\Input::get('action',  false) == 'case'){
			$cid = $seller->case_category;
			$entity_name = '案例';
		}else if(\Input::get('action',  false) == 'page'){
			$cid = $seller->page_category;
			$entity_name = '页面';
		}else if(\Input::get('action',  false) == 'ad'){
			$cid = $seller->ad_category;
			$entity_name = '广告';
		}	
	}
	
?>
<div class="row">
	<div class="col-xs-12">
		<!-- PAGE CONTENT BEGINS -->
		<form class="form-horizontal" method="post" role="form">
			<!-- #section:elements.form -->
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <?php echo $entity_name; ?>标题 </label>
				<div class="col-sm-9">
					<input type="text" class="col-xs-10 col-sm-5 col-md-7" id="title" name="title" placeholder="<?php echo $entity_name; ?>标题" value="<?php echo isset($item) && $item ? $item->title : ''; ?>">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <?php echo $entity_name; ?>子标题 </label>
				<div class="col-sm-9">
					<input type="text" class="col-xs-10 col-sm-5 col-md-7" id="sub_title" name="sub_title" placeholder="<?php echo $entity_name; ?>子标题" value="<?php echo isset($item) && $item ? $item->sub_title : ''; ?>">
				</div>
			</div>
			<?php if($cid != $seller->page_category){ ?>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <?php echo $entity_name; ?>类目 </label>
				<div class="col-sm-9">
					<select class="col-xs-10 col-sm-5 col-md-7" id="category_id" name="category_id">
                    </select>
				</div>
			</div>
			<?php }else{ ?>
			<input type="hidden" name="category_id" value="<?php echo $cid; ?>">
			<?php } ?>
			

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 缩略图 </label>
				<div class="col-sm-9">					
					<div class="input-group col-xs-10 col-sm-7">
						<input type="text" class="form-control" id="thumbnail" name="thumbnail" placeholder="外链地址或上传本地图片" value="<?php echo isset($item) && $item ? $item->thumbnail : ''; ?>" data-toggle="modal" data-target="#modal-upload">
						<span class="input-group-addon">
							<a href="#" data-panel="qrcode" data-toggle="modal" data-target="#modal-upload"><i class="ace-icon fa fa-upload"></i></a>
						</span>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <?php echo $entity_name; ?>详情 </label>
				<div class="col-sx-7 col-sm-7 col-md-7">
					<textarea class="" id="body" name="body" placeholder="<?php echo $entity_name; ?>内容" role="editor" style="height:300px;"><?php echo isset($item) && $item ? $item->body : ''; ?></textarea>
				</div>
			</div>
			<?php if(in_array($cid, array($seller->article_category, $seller->case_category))){ ?>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 其它选项 </label>
				<div class="col-sm-9">
					<input type="checkbox" id="stick" name="stick" value="0"> <label>是否置顶</label>
				</div>
			</div>
			<?php }?>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 链接地址 </label>
				<div class="col-sm-9">
					<input type="text" class="col-xs-10 col-sm-5 col-md-7" id="url" name="url" placeholder="外链地址"  value="<?php echo isset($item) && $item ? $item->url : ''; ?>">
				</div>
			</div>

			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check bigger-110"></i>
						提交
					</button>

					&nbsp; &nbsp; &nbsp;
					<button class="btn" type="reset">
						<i class="ace-icon fa fa-undo bigger-110"></i>
						重置
					</button>
				</div>
			</div>
		</form><!-- PAGE CONTENT ENDS -->
	</div><!-- /.col -->
</div><!-- /.row -->

<?php echo render('ace/public/alert_message'); ?>

<script type="text/javascript">
  var path = '<?php echo \Input::get('action', false) == 'car_feature' ? 'car' : 'article'; ?>';
  var imgpanel = '';
  
  function callback(file, data){
      var json = eval('(' + data + ')');
      if(json.status == 'succ'){
          $("#thumbnail").val(json.data);
      }else{
          alert(json.msg);
      }
  }
</script>
<?php echo render('tools/upload'); ?>

<script type="text/javascript">
$(function(){
	
	$.get('/admin/category?cid=<?php echo $cid; ?>&action=all', 
		function(data, status){
			if(data.status == 'err'){
				return;
			}
			$('#category_id').empty();
			childrens(data.data, '');
		}, 'json');
});

function childrens(items, addspan){
	for (var i = 0; i < items.length; i++) {
		$('#category_id').append('<option value="' + items[i].id + '">' + addspan + items[i].name + '</option>');
		if(items[i].children != undefined){
			childrens(items[i].children, addspan + '--');
		}
	};
}
</script>

<script type="text/javascript" src="/assets/third-party/editor/kindeditor-min.js"></script>
<script charset="utf-8" src="/assets/third-party/editor/lang/zh_CN.js"></script>
<script type="text/javascript">
$(function(){
    KindEditor.ready(function(K){
        window.editor = K.create('textarea[role="editor"]');
    });
});
</script>

